/*
 Copyright (c) Whitemice Consulting, 2007, 2008, 2009
 Adam Tauno Williams <awilliam@whitemice.org>
 License: MIT/X11

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
*/
using System;
using Gtk;
using HollyLibrary;
using Whitemice.ZOGI;
using Whitemice.ZOGI.GtkWidgets;
using Whitemice.ZOGI.GtkForms;

namespace Whitemice.ZOGI.GtkFolios
{
	[System.ComponentModel.Category("widget")]
	[System.ComponentModel.ToolboxItem(true)]
	public class ProjectFolio : EntityFolio
	{
		protected ProjectDetailForm                   form;
		protected ContactTab                          contacts;
		protected EnterpriseTab                       enterprises;
		protected ObjectLinkTab                       objectLinks;
		protected TaskTab                             tasks;
		protected NoteTab                             notes;
		protected DocumentsTab                        documents;
		
		public    EventHandler                        OnTabThaw;
		
		public ProjectFolio() : base()
		{
			tasks = new TaskTab();
			tasks.OnTaskEvent += new EntityEventHandler(TaskEvent);
			tasks.OnDataReceived += new EventHandler(TabThaw);
			tasks.PopupEnabled = true;
			tasks.ProjectVisible = false;
			
			form = new ProjectDetailForm();
			contacts = new ContactTab();
			contacts.OnDataReceived += new EventHandler(TabThaw);
			enterprises = new EnterpriseTab();
			enterprises.OnDataReceived += new EventHandler(TabThaw);
			
			objectLinks = new ObjectLinkTab();
			notes = new NoteTab("Project");
			documents = new DocumentsTab();
			      
			this.AppendPage(form, new Label("Details"));
			this.AppendPage(enterprises, new Label("Enterprises"));
			this.AppendPage(contacts, new Label("Contacts"));
			this.AppendPage(tasks, new Label("Tasks"));
			this.AppendPage(documents, new Label("Documents"));
			this.AppendPage(notes, new Label("Notes"));
			this.AppendPage(objectLinks, new Label("Links"));
			foreach(Widget w in this.Children)
				w.Show();
			this.ShowAll();
		} // end ctor
		
		protected void TabThaw(object sender, EventArgs args)
		{
      this.ZLOG(string.Format("Thawing {0}", sender));
		  if (OnTabThaw != null)
		    OnTabThaw(sender, args);
		} // end TabThaw
		
		public EnterpriseTab EnterpriseTab
		{ get { return enterprises; } }
		
		public ContactTab ContactTab
		{ get { return contacts; } }
		
		public TaskTab TaskTab
		{ get { return tasks; } }
		
		public NoteTab NoteTab
		{ get { return notes; } }		
		
		public ObjectLinkTab LinksTab
		{ get { return objectLinks; } } 
		
		public EntityEventHandler OnTaskEvent;
		
		protected void TaskEvent(Entity _entity, object _context, Exception _ex)
		{
		  this.ZLOG("ProjectFolio::TaskEvent");
		  if (OnTaskEvent == null)
		    this.ZLOG("ProjectFolio::TaskEvent - no handler");
		  else
		    OnTaskEvent(_entity, _context, _ex); 
		} // end TaskEvent
	} // end Project Folio
} // end namespace

